package com.yunjing.tabdemo;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class TabFragment extends Fragment {

    private static final String TAG = "TabFragmentTag";
    private static final String KEY_ORDER_LIST_FRAGMENT_DATA = "key_order_list_fragment_data";
    private TabEntity mTabEntity;
    private TextView textView;

    public static TabFragment newInstance(TabEntity tabEntity) {
        Log.d(TAG, "newInstance: tab:" + tabEntity.getTabName());
        TabFragment fragment = new TabFragment();
        Bundle args = new Bundle();
        args.putSerializable(KEY_ORDER_LIST_FRAGMENT_DATA, tabEntity);
        fragment.setArguments(args);
        return fragment;
    }

    public static void setTabEntity(TabFragment fragment, TabEntity tabEntity) {
        Bundle args = new Bundle();
        args.putSerializable(KEY_ORDER_LIST_FRAGMENT_DATA, tabEntity);
        fragment.setArguments(args);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.tab_fragment, container, false);
        textView = view.findViewById(R.id.fragment_tv);
        Log.d(TAG, "onCreateView: ");
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onActivityCreated: ");
        super.onActivityCreated(savedInstanceState);
        if (getArguments() != null) {
            mTabEntity = (TabEntity) getArguments().getSerializable(KEY_ORDER_LIST_FRAGMENT_DATA);
            if (mTabEntity.isAlong()) {
                textView.setText(mTabEntity.getTabName() + "(下料)");
            } else {
                textView.setText(mTabEntity.getTabName() + "(倒运)");
            }

            Log.d(TAG, "onActivityCreated: mTabEntity:" + mTabEntity.getTabName());
        }
    }


}
